fix stringop-overflow= warning with g++-9. (#362)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Fri, 24 May 2019 12:12:07 +0000 (06:12 -0600)
committerGitHub <noreply@github.com>
Fri, 24 May 2019 12:12:07 +0000 (06:12 -0600)
Additionally, produce a warning for any conversion errors when
reading XT_TIMET_TIME_MS fields in an xcsv file.

xcsv.cc

diff --git a/xcsv.cc b/xcsv.cc
index f23b615477d8b4e902197f5b7170cb34319cfe5c..2526be075b37d8c3f790aea00b65e9ade346e2a2 100644 (file)
--- a/xcsv.cc
+++ b/xcsv.cc
@@ -803,20 +803,10 @@ xcsv_parse_val(const char* s, Waypoint* wpt, const field_map& fmp,
     break;
   case XT_TIMET_TIME_MS: {
     /* Time as time_t in milliseconds */
-    int s_len = strlen(s);
-    if (s_len < 4) {
-      /* less than 1 epochsecond, an unusual case */
-      wpt->SetCreationTime(0, atoi(s));
-    } else {
-      char buff[32];
-      int off = s_len - 3;
-      strncpy(buff, s, off);
-      buff[off] = '\0';
-      time_t t = (time_t) atol(buff);
-      s += off;
-      strncpy(buff, s, 3);
-      buff[3] = '\0';
-      wpt->SetCreationTime(t, atoi(buff));
+    bool ok;
+    wpt->SetCreationTime(QDateTime::fromMSecsSinceEpoch(QString(s).toLongLong(&ok)));
+    if (!ok) {
+      warning("parse of string '%s' on line number %d as TIMET_TIME_MS failed.\n", s, line_no);
     }
   }
   break;